<template>
  <section class="container">
    <img src="../static/img/logo.png" alt="Nuxt.js Logo" class="logo" />
    <h1 class="title">
      This page is loaded from the {{ name }}
    </h1>
    <h2 class="info" v-if="name === 'client'">
      Please refresh the page
    </h2>
    <nuxt-link class="button" to="/">
      Home page
    </nuxt-link>
  </section>
</template>
<script>
// import { mapState } from 'vuex'
export default {
  asyncData(ctx) {
    return {
      name: ctx.req ? 'server' : 'client'
    }
  },
  head() {
    return {
      title: `test page`
    }
  },
  beforeMount() {
    const wx = window.wx
    const url = encodeURIComponent(window.location.href.split('#')[0])
    this.$store.dispatch('getWxSignature', url).then((res) => {
      if (res.data.success) {
        const params = res.data.params
        wx.config({
          debug: true,
          appId: params.appID,
          timestamp: params.timeStamp,
          nonceStr: params.noncestr,
          signature: params.signature,
          jsApiList: [
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'onMenuShareTimeline',
            'hideAllNonBaseMenuItem',
            'showAllNonBaseMenuItem'
          ]
        })
        wx.ready(() => {
          wx.hideAllNonBaseMenuItem()
          console.log('success')
        })
      }
    })
  }
}
</script>

<style scoped>
.title
{
  margin-top: 50px;
}
.info
{
  font-weight: 300;
  color: #9aabb1;
  margin: 0;
  margin-top: 10px;
}
.button
{
  margin-top: 50px;
}
</style>
